package com.aatrox.bhsypro.controller;

import com.aatrox.bhsypro.entity.BUser;
import com.aatrox.bhsypro.service.BUserService;
import com.aatrox.bhsypro.util.Generate;
import com.aatrox.bhsypro.util.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

/**
 * 登录注册 ajax
 */
@RestController
@SessionAttributes({"bUser"})
public class BloginAjaxController {
    protected static final Logger logger = LoggerFactory.getLogger(BloginAjaxController.class);
    @Autowired
    BUserService bUserService;
    ///注册
    @RequestMapping("/zc")
    @ResponseBody
    public JsonResult zc(String yhm, String nc, ModelMap m){
        Integer itg = bUserService.selUserNameIsCf(nc);
        logger.info("昵称查询为:"+itg);
        HashMap hm = new HashMap();
        if (itg!=null){
            return new JsonResult(500,"改昵称已被注册");
        }else {
            String pass= Generate.shen();
            bUserService.zc(new BUser(nc,yhm,pass));
            hm.put("yhm",yhm);
            hm.put("pass",pass);
            return new JsonResult(200,"注册成功",hm);
        }
    }

}

